package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据条件获取购物车的id
     * @param shoppingCart
     * @return
     */
    Long getId(ShoppingCart shoppingCart);

    /**
     * 更新数量
     * @param id
     */
    @Update("update shopping_cart set number = number + 1 where id = #{id}")
    void updateNumber(Long id);

    /**
     * 插入菜品或套餐到购物车中
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "VALUES (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 查看该用户购物车中的所有数据
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> list(Long userId);

    void delete(ShoppingCart shoppingCart);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

    void insertBatch(List<ShoppingCart> shoppingCartList);
}
